//
//  HMHomeHeadView.m
//  LoveFreshBeen
//
//  Created by huodian on 16/10/20.
//  Copyright © 2016年 魏根. All rights reserved.
//

#import "HMHomeHeadView.h"

#import "HMHomeFirstModel.h"

#import <UIImageView+WebCache.h>

@interface HMHomeHeadView()

@property(nonatomic,weak)UIImageView* imageView;

@property(nonatomic,strong)UILabel* nameLable;

@property(nonatomic,strong)UILabel* priceLable;

@property(nonatomic,strong)UILabel* messageLable;

@property(nonatomic,strong)UILabel* weightLable;

@property(nonatomic,strong)UILabel* lable5;





@end



@implementation HMHomeHeadView


-(void)setModel:(HMHomeFirstModel *)model
{
    _model = model;
    
    self.nameLable.text = model.name;
    
    self.priceLable.textColor = [UIColor redColor];
    
    self.priceLable.text = [NSString stringWithFormat:@"$%.1f  $%.1f",model.partner_price,model.market_price];
    
    NSMutableAttributedString* strM = [[NSMutableAttributedString alloc]initWithString:self.priceLable.text];
    
    NSRange rang = [self.priceLable.text rangeOfString:[NSString stringWithFormat:@" $%.1f",model.market_price]];
    [strM addAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor],NSStrikethroughStyleAttributeName:@1} range:rang];
    
    
    
    self.priceLable.attributedText = strM;
    
  
    self.weightLable.text = model.specifics;
    
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:[UIImage imageNamed:@"v2_placeholder_full_size"]];
    
    [self layoutIfNeeded];
    
   
    
}

-(instancetype)init
{
    if (self == [super init])
    {
        
        self.backgroundColor = [UIColor whiteColor];
        
        [self setMyUI];
        
    }
    return self;
    
    
}
-(void)setMyUI
{
    
//    self.backgroundColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:239/255.0 alpha:1];
    UIImageView* imageView = [[UIImageView alloc]init];
    
    self.imageView = imageView;
    
    imageView.contentMode =  UIViewContentModeScaleAspectFit;
    
    [self addSubview:imageView];
    
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.leading.trailing.equalTo(self);
        
        make.height.equalTo(@300);
        
    }];
    
    
    UIView* first = [[UIView alloc]init];
    
    [self addSubview:first];
    
    [first mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.leading.trailing.equalTo(self);
        
        make.top.equalTo(imageView.mas_bottom).offset(10);
        
        make.height.equalTo(@1);
        
    }];
    
    
    UILabel* lable1 = [[UILabel alloc]init];
    
    
    self.nameLable = lable1;
    
    [self addSubview:lable1];
    
    [lable1 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(first.mas_bottom).offset(10);
        
        make.leading.equalTo(self).offset(20);
        
        make.height.equalTo(@20);

    }];
    
    
    UILabel* lable2 = [[UILabel alloc]init];
    
    self.priceLable = lable2;
    
    [self addSubview:lable2];
    
    [lable2 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(lable1.mas_bottom).offset(5);
        
        make.leading.equalTo(self).offset(20);
        
        make.height.equalTo(@18);
        
    }];
    
    UIView* second = [[UIView alloc]init];
    
    second.backgroundColor = [UIColor lightGrayColor];
    
    [self addSubview:second];
    
    [second mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.leading.trailing.equalTo(self);
        
        make.top.equalTo(lable2.mas_bottom).offset(10);
        
        make.height.equalTo(@1);
        
    }];
    
    UIButton* redBtn = [[UIButton alloc]init];
    
    [redBtn setBackgroundImage:[UIImage imageNamed:@"zengsong"] forState:UIControlStateNormal];
    
    [self addSubview:redBtn];
    
    [redBtn mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.leading.equalTo(self).offset(20);
        
        make.top.equalTo(second.mas_bottom).offset(10);
        
        make.width.equalTo(@50);
        
        make.height.equalTo(@20);
        
    }];
    
    UILabel* lable3 = [[UILabel alloc]init];
    
    self.messageLable = lable3;
    
    [self addSubview:lable3];
    
    [lable3 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.leading.equalTo(redBtn.mas_trailing).offset(20);
        
        make.centerY.equalTo(redBtn.mas_centerY);
        
        make.height.equalTo(@20);
        
    }];
    
    
    UIView* three = [[UIView alloc]init];
    
    three.backgroundColor = [UIColor lightGrayColor];
    
    [self addSubview:three];
    
    [three mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.leading.trailing.equalTo(self);
        
        make.top.equalTo(lable3.mas_bottom).offset(10);
        
        make.height.equalTo(@1);
        
    }];
    
    UILabel* lable4 = [[UILabel alloc]init];
    
    lable4.textColor = [UIColor lightGrayColor];
    
    lable4.text = @"品    牌";
    
    [self addSubview:lable4];
    
    [lable4 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(three.mas_bottom).offset(10);
        
        make.leading.equalTo(self).offset(20);
        
        make.width.equalTo(@80);
        
        make.height.equalTo(@20);
        
        
    }];
    
    UILabel* lable5 = [[UILabel alloc]init];
    
    
    lable5.text = @"爱鲜蜂";
    
    [self addSubview:lable5];
    
    [lable5 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.equalTo(lable4.mas_centerY);
        
        make.leading.equalTo(lable4.mas_trailing).offset(20);
        
        make.height.equalTo(@18);
        
    }];
    
    
    UIView* four = [[UIView alloc]init];
    
    four.backgroundColor = [UIColor lightGrayColor];
    
    [self addSubview:four];
    
    [four mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.leading.trailing.equalTo(self);
        
        make.top.equalTo(lable4.mas_bottom).offset(10);
        
        make.height.equalTo(@1);
        
    }];
    
    UILabel* lable6 = [[UILabel alloc]init];
    
    lable6.textColor = [UIColor lightGrayColor];
    
    lable6.text = @"产品规格";
    
    [self addSubview:lable6];
    
    [lable6 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(four.mas_bottom).offset(10);
        
        make.leading.equalTo(self).offset(20);
        
        make.width.equalTo(@80);
        
        make.height.equalTo(@20);
        
        
    }];
    
    UILabel* lable7 = [[UILabel alloc]init];
    
    self.weightLable = lable7;
    
    [self addSubview:lable7];
    
    [lable7 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(lable6.mas_centerY);
        
        make.leading.equalTo(lable6.mas_trailing).offset(20);
        
        make.height.equalTo(@18);
        
    }];
    
    
    UIView* five = [[UIView alloc]init];
    
    [self addSubview:five];
    
    [five mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.leading.trailing.equalTo(self);
        
        make.top.equalTo(lable7.mas_bottom).offset(10);
        
        make.height.equalTo(@1);
        
    }];
    
    UILabel* lable8 = [[UILabel alloc]init];
    
    lable8.textColor = [UIColor lightGrayColor];
    
    lable8.text = @"图文详情";
    
    [self addSubview:lable8];
    
    [lable8 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(five.mas_bottom).offset(10);
        
        make.leading.equalTo(self).offset(20);
        
        make.width.equalTo(@80);
        
        make.height.equalTo(@20);
        
        
    }];
    
    UILabel* lable9 = [[UILabel alloc]init];
    
    lable9.textColor = [UIColor lightGrayColor];
    
    lable9.text = @"温馨提示:";
    
    [self addSubview:lable9];
    
    [lable9 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(lable8.mas_bottom).offset(15);
        
        make.leading.equalTo(self).offset(20);
        
        make.width.equalTo(@80);
        
        make.height.equalTo(@20);
        
        
    }];
    
    UILabel* lable10 = [[UILabel alloc]init];
    
    lable10.textColor = [UIColor lightGrayColor];
    
    lable10.numberOfLines = 0;
    
    lable10.font = [UIFont systemFontOfSize:14];
    
    lable10.text = @"商品签收后如果有问题请再24小时类联系400845678934567,并将商品和包装保留好发给客服";
    lable10.textColor = [UIColor redColor];
    
    [self addSubview:lable10];
    
    [lable10 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(lable9.mas_bottom).offset(5);
        
        make.leading.equalTo(self).offset(20);
        
        make.trailing.equalTo(self).offset(-20);
        
        make.width.equalTo(@30);
        
    }];
    
    
    
    
    
}
-(void)drawRect:(CGRect)rect
{
   
    
    
    
}

@end
